package com.newlink.building.common_base.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;

import com.newlink.building.common_base.utils.Base_DensityUtil;

/**
 * @Author: Jake
 * @Date: 2023-04-15
 * @Description:
 */

public class AutoFixReletaiveLayout extends RelativeLayout {

    private int mRadius = 20;

    public AutoFixReletaiveLayout(Context context) {
        super(context);
    }

    public AutoFixReletaiveLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public AutoFixReletaiveLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    public void setRadius(int radius) {
        mRadius = radius;
        invalidate();
    }


    @Override
    protected void dispatchDraw(Canvas canvas) {
        Path path = new Path();
        RectF rectF = new RectF();
        rectF.set(0, 0, getWidth(), getHeight());
        path.addRoundRect(rectF, Base_DensityUtil.dp2px(getContext(), mRadius), Base_DensityUtil.dp2px(getContext(), mRadius), Path.Direction.CW);
        canvas.clipPath(path);
        super.dispatchDraw(canvas);
    }


}